Imports Microsoft.Win32
Imports System.Data.OleDb

Module Start

    Sub Main()
        Call CaricaPath()
        Call CaricaDati()
    End Sub

    Private Sub CaricaPath()
        ' carica i dati dal registro
        pathDb.pathDbLe = Registry.CurrentUser.OpenSubKey("Software", False).OpenSubKey("Glv").GetValue("pathDbLe").ToString
        pathDb.pathDbGlv = Registry.CurrentUser.OpenSubKey("Software", False).OpenSubKey("Glv").GetValue("pathDbGlv").ToString
        pathExe.pathLe = Registry.CurrentUser.OpenSubKey("Software", False).OpenSubKey("Glv").GetValue("pathLe").ToString
        pathExe.pathGlv = Registry.CurrentUser.OpenSubKey("Software", False).OpenSubKey("Glv").GetValue("pathGlv").ToString
    End Sub

    Public Sub CaricaDati()
        Dim cnDb As OleDbConnection
        Dim cmDb As OleDbCommand
        Dim drDb As OleDbDataReader

        ' imposta le strinche di connessione
        strConnessioneClienti = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathDb.pathDbLe & "\Db_LampadeEterne.mdb;Persist Security Info=False"
        strConnessioneDefunti = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathDb.pathDbGlv & "\Database.mdb;Persist Security Info=False"

        cnDb = New OleDbConnection(strConnessioneDefunti)
        cnDb.Open()
        cmDb = New OleDbCommand("SELECT * FROM CONGREGA", cnDb)
        drDb = cmDb.ExecuteReader

        ' carica i vettori dall'archivio di GLV
        Do While drDb.Read
            v_congreghe.Add(drDb.Item("NOME"))
        Loop
        cnDb.Close()

        ' carica i dati dall archivio di LE
        cnDb = New OleDbConnection(strConnessioneClienti)
        cnDb.Open()
        cmDb = New OleDbCommand("SELECT * FROM DATI", cnDb)
        drDb = cmDb.ExecuteReader
        If drDb.Read Then
            iva = CSng(drDb.Item("IVA"))
            spese = CSng(drDb.Item("SPESE_ALLACCIAMENTO"))
            costoLampada = CSng(drDb.Item("IMPORTO_LAMPADA"))
            numCopieContratto = CSng(drDb.Item("NUM_COPIE"))
        Else
            iva = 0
            spese = 0
            costoLampada = 0
            numCopieContratto = 1
        End If

        cnDb.Close()
    End Sub

End Module
